﻿//
//    Copyright (c) 2018 camunda services GmbH (info@camunda.com)
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

using System;
using System.Threading;
using System.Threading.Tasks;

namespace Zeebe.Client.Api.Commands
{
    /// <summary>
    /// The is a general final command step for the fluent command API, which defines the send method.
    /// </summary>
    /// <typeparam name="T">the type of the command response.</typeparam>
    public interface IFinalCommandStep<T>
    {
        /// <summary>
        /// Sends the command to the Zeebe broker. This operation is asynchronous. In case of success, the
        /// task returns the event that was generated by the Zeebe broker in response to the command.
        ///
        /// <para>Use <c>await ...Send();</c> to wait until the response is available.</para>
        ///
        /// <example>
        /// <code>
        /// T response = await command.Send();
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="timeout">the time span after request should be timed out.</param>
        /// <returns>a task tracking state of success/failure of the command.</returns>
        Task<T> Send(TimeSpan? timeout = null);

        /// <summary>
        /// Sends the command to the Zeebe broker. This operation is asynchronous. In case of success, the
        /// task returns the event that was generated by the Zeebe broker in response to the command.
        ///
        /// <para>Use <c>await ...Send(CancellationToken.None);</c> to wait until the response is available.</para>
        ///
        /// <example>
        /// <code>
        /// T response = await command.Send(CancellationToken.None);
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="token">the token that manages the cancellation of the request.</param>
        /// <returns>a task tracking state of success/failure of the command.</returns>
        Task<T> Send(CancellationToken token);
    }
}
